$(function () {
    $('.payment .weui-check__label').on('click',function(){
        $('.payment i').each(function(){
            if($(this).hasClass('micon-checked')){
                $(this).removeClass('micon-checked');
                $(this).prev('input').removeAttr('checked');
            }
        });
        $(this).find('i').addClass('micon-checked');
        $(this).find('input').attr('checked',true);
    });
    $('.paymentPassword-btn').click(function (e) {
        e.preventDefault();
        that=$('.passwordList>input');
        var psdLength=that.val().length;
        for(var i=0;i<psdLength;i++){
            $('.passwordList span').eq(i).html('');
        }
        that.val('');
        $.closePopup();
    });
    $('.password-count').on('click','a.number',function (e) {
        e.preventDefault();
        var t=$(this).attr('href');
        var va=$('.passwordList>input').val();
        $('.passwordList>input').val(va+=t);
        that=$('.passwordList>input');
        var psdLength=that.val().length;
        $('.passwordList span').each(function(){
            $(this).html('');
        });
        for(var i=0;i<psdLength;i++){
            $('.passwordList span').eq(i).html('·');
        }
        if(that.val().length>=6){
            $.showLoading();
            var num=that.val().substr(0,6);
            // 验证安全密码是否正确
            $.ajax({
                type : 'POST',
                url : '/index/pay/check_safe_password',
                data : {
                    safe_password : num
                },
                dataType : 'json',
                success : function(msg) {
                    if (msg.code == 200) {
                        // 如果正确就提交支付信息
                        $.closePopup();
                        if ($(".withdraw-btn").length > 0) {
                            // 提现
                            withdraw_apply_for(SCOPE.withraw_data);
                        } else {
                            // 支付
                            instation_pay(SCOPE.order_data);
                        }
                    } else {
                        // 如果密码错误，清空密码重新输入
                        $.toptip(msg.msg, 'error');
                        $.hideLoading();
                        that.val(num);
                        for(var i=0;i<psdLength;i++){
                            $('.passwordList span').eq(i).html('');
                        }
                        that.val('');
                        $(".weui-loadmore").hide();
                    }
                }
            })
        }
    });
    $('.password-count .subduction').click(function (e) {
        e.preventDefault();
        that=$('.passwordList>input');
        var psdLength=that.val().length;
        $('.passwordList span').eq(psdLength-1).html('');
        var num=that.val().substr(0,psdLength-1);
        that.val(num)
    })
});